package com.yanxu;

import jdk.nashorn.internal.runtime.Scope;

import java.io.*;
import java.net.InetSocketAddress;
import java.net.Socket;

/**
 * @author 折戟沉沙铁未销
 * @version V1.0
 * @date 2025-05-29-2025
 * @Description: 客户端
 */
public class Client {
    public static void main(String[] args) throws IOException {
        Socket socket = null;
        try {
            //socket=new Socket();
            //socket.bind(new InetSocketAddress("127.0.0.1",5678));
            //socket.connect(new InetSocketAddress("192.168.1.30",9999));
            socket = new Socket("127.0.0.1", 9999);


            BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
            BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));

            BufferedReader consoleReader = new BufferedReader(
                    new InputStreamReader(System.in)
            );
            String data = consoleReader.readLine();

            writer.write(data + "\n");
            writer.flush();

            String msg = reader.readLine();
            System.out.println(msg);

        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            socket.close();
        }


    }
}